home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / hypercar / mactool / thinkcgu.sit / app ƒ / menubar.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-17  |  1.5 KB  |  67 lines

  1. # ifdef        THINK_C
  2. /*
  3. *    FILE:        menubar.c
  4. *    AUTHOR:        R. Gonzalez
  5. *    CREATED:    August 28, 1990
  6. *
  7. *    Defines menu bar methods, for Macintosh applications.  Requires
  8. *    Macintosh header files defined in MacHeaders; calls Macintosh Toolbox
  9. *    ROM routines.
  10. */
  11.  
  12. # include    <string.h>
  13. # include    "menubar.h"
  14.  
  15. # define    MAX_LENGTH    80
  16.  
  17. /************************************************************************
  18. *    set menu bar
  19. ************************************************************************/
  20. void    Menu_Bar::set(Menu *menu)
  21. {
  22.     MenuHandle    menu_hand;
  23.     int            menu_num,
  24.                 item;
  25.     char        name[MAX_LENGTH];
  26.     
  27.     ClearMenuBar();
  28.  
  29.     for (menu_num=1 ; menu_num<=menu->num_menus ; menu_num++)
  30.     {
  31.         strcpy(name,menu->command[menu_num][0]);
  32.         menu_hand = NewMenu(menu_num,CtoPstr(name));
  33.         InsertMenu(menu_hand,0);
  34.         for (item=1 ; item<menu->num_items[menu_num] ; item++)
  35.         {
  36.             strcpy(name,menu->command[menu_num][item]);
  37.             AppendMenu(menu_hand,CtoPstr(name));
  38.         }
  39.     }
  40.     
  41.     DrawMenuBar();
  42. }
  43.  
  44. /************************************************************************
  45. *    get command name
  46. ************************************************************************/
  47. void    Menu_Bar::get_command(char command[],EventRecord theEvent)
  48. {
  49.     long int    menuChoice;
  50.     int            theMenu,
  51.                 theItem;
  52.     char        selection[MAX_LENGTH];
  53.     
  54.     menuChoice = MenuSelect(theEvent.where);
  55.     
  56.     if (menuChoice == 0)
  57.         strcpy(command,"");
  58.     else
  59.     {
  60.         theMenu = HiWord(menuChoice);
  61.         theItem = LoWord(menuChoice);
  62.         GetItem(GetMHandle(theMenu),theItem,selection);
  63.         strcpy(command,PtoCstr(selection));
  64.     }
  65. }
  66. # endif
  67.